#pragma once

#include <QtGui/QMainWindow>
#include <QtCore/QVector>
#include "arma_vector.h"

class QAction;
class QToolBar;
class QKeyEvent;
class QComboBox;
class Problem;
class MainWindow;
class Plotter;
class Axis;
class QLineEdit;
class QCheckBox;

class DrawArea : public QWidget
{
  MainWindow* m_mainWindow;
  QPointF m_currentPoint;
public:
  DrawArea(MainWindow* mainWindow, QWidget* parent = 0) : QWidget(parent), m_mainWindow(mainWindow), m_currentPoint(0, 0) {}
  //void setProblem(Problem *problem) { m_problem = problem; }
  void paintEvent (QPaintEvent *e);
  void mouseDoubleClickEvent(QMouseEvent *e);
  const QPointF& currentPoint() const { return m_currentPoint; }
  void set_currentPoint(const QPointF& currentPoint) { m_currentPoint = currentPoint; }
};

class MainWindow : public QMainWindow
{
	Q_OBJECT
public:
	MainWindow(const QString& windowName, QWidget *parent = 0);
	~MainWindow();
public slots:
  void slot_loadData();
  void slot_solve();
  void slot_findNN();
  void slot_findKNN();
  void slot_problemChanged(int);
  void slot_generateData();
protected:
  DrawArea *m_drawArea;
  QAction *m_actLoadData, *m_actSolve, *m_actFindNN, *m_actFindKNN,
          *m_actGenerateData;
  QToolBar *m_tbTools, *m_tbPlotBox;
  QComboBox *m_cmbProblem;
  QLineEdit *m_edtXMIN, *m_edtXMAX, *m_edtYMIN, *m_edtYMAX, *m_edtKNN;
  QCheckBox *m_chkBinary;

  Problem *m_currentProblem, *m_convexHullProblem, *m_kdTreeBuildProblem,
          *m_matchingProblem, *m_maximumMatchingProblem,
          *m_auctionMatchingProblem, *m_auctionMatchingKDTreeProblem;
  QVector<Problem*> m_problem;
  std::vector<vec> m_kNN;

	void createActions();
	void createWidgets();
	void createToolbar();
	void createLayout();
	void connectSignals();

  void keyPressEvent(QKeyEvent *event);
public:
  void draw(QWidget* drawArea);
  void preparePlotter(Plotter& pl);
  void prepareAxis(Axis& axis);
};
